﻿using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Services;
using IntelligentAgriculture.WebAPI.Application.Command.SheepCommand;
using IntelligentAgriculture.WebAPI.Application.Command.UnitCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.UnitCommandHandler
{
    public class UnitQueryCommandHandler : IRequestHandler<UnitQueryCommand, Results<PageOutput<UnitListOutPut>>>
    {



        private readonly IUnitService unitService;
        private readonly ILogger<UnitQueryCommandHandler> logger;
        public UnitQueryCommandHandler(IUnitService unitService, ILogger<UnitQueryCommandHandler> logger)
        {
            this.unitService = unitService;
            this.logger = logger;
        }


        /// <summary>
        /// 单位查询列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<PageOutput<UnitListOutPut>>> Handle(UnitQueryCommand request, CancellationToken cancellationToken)
        {
            var list = await unitService.GetUnitList(request.Unit);
            var results = Results<PageOutput<UnitListOutPut>>.DataResult(list);
            return results;
        }





    }




}
